package com.helsinki.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.helsinki.mapper.OrdersMapper;
import com.helsinki.pojo.Orders;
import com.helsinki.pojo.Product;
import com.helsinki.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;
    @Override
    public Orders queryById(String id) {
        return ordersMapper.findById(id);
    }

    @Override
    public PageInfo<Orders> queryAll(Integer pageNum, Integer pageSize) {
        // 只有在要分页的查询之前才能设置分页信息
        PageHelper.startPage(pageNum, pageSize);
        List<Orders> list = ordersMapper.findAll();
        // PageInfo 封装了所有的分页信息
        return new PageInfo<>(list);
    }

    @Override
    public void updateStatus(String[] ids, int status) {
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                ordersMapper.updateStatus(id, status);
            }
        }
    }

}